import "./sql";

// const client = new Client();
// client.getAll();

import { load } from "cheerio";

import axios from "axios";
import { add } from "./sql";

(async function () {
  const data = await axios.get(`https://www.conanpedia.com/名侦探柯南电视动画`);
  const $ = load(data.data);
  const tables = $("table").map((i, el) => el);

  for (let i = 0; i <= 28; i++) {
    const trs = $(tables[i])
      .find("tbody tr")
      .map((i, el) => el);

    for (let j = 1; j < trs.length; j++) {
      const text = $(trs[j]).text();
      const ds = text.split("\n").filter((i) => i.length > 0);
      const [episode_jp, episode_cn, titile_cn, title_jp, time, k, commic] = ds;
      console.log(`正在插入：${titile_cn}`);
      await add({
        episode_jp: +episode_jp,
        episode_cn: episode_cn.slice(0, 20),
        titile_cn,
        title_jp,
        time,
        commic,
      });
    }
  }
})();
